package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.getTimer;
	
	/**
	 * ...
	 * @author Chen Ran
	 */
	public class XMLTest extends Sprite 
	{
		
		public function XMLTest():void 
		{
			const count:int = 100000;
			var xml:XML = XMLData.data;
			
			var i:int;
			var timer:uint;
			
			var tmp:XMLList;
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.avatar;
			}
			trace('valid E4X:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.child('avatar');
			}
			trace('valid API:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.ppp;
			}
			trace('invalid E4X:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.child('ppp');
			}
			trace('invalid API:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.avatar.slide;
			}
			trace('mulit-valid E4X:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.child('avatar').child('slide');
			}
			trace('mulit-valid API:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.ppp.qqq;
			}
			trace('mulit-invalid E4X:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.child('ppp').child('qqq');
			}
			trace('mulit-invalid API:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.*;
			}
			trace('all E4X:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.children();
			}
			trace('all API:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.@id;
			}
			trace('attribute E4X:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.attribute('id');
			}
			trace('attribute API:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.@*;
			}
			trace('all attributes E4X:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				tmp = xml.attributes();
			}
			trace('all attributes API:', getTimer() - timer);
			
			var copy:XML = XMLData.data.copy();
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				copy == xml;
			}
			trace('compare use ==:', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				copy.toXMLString() == xml.toXMLString();
			}
			trace('compare use toXMLString():', getTimer() - timer);
			
			timer = getTimer();
			for (i = 0; i < count; ++i)
			{
				copy === xml;
			}
			trace('compare use ===:', getTimer() - timer);
		}
		
	}
	
}

class XMLData
{
	internal static var data:XML = <map id='test'>
    <avatar id="candy" stance="walk" alpha="0">
      <slide x="70" length="2"/>
      <fadeIn length="2"/>
    </avatar>
    <wait time="1.7"/>
  </map>
}